<!DOCTYPE html>
<html lang="en">

<head>
	<!-- <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.2.0/css/bootstrap-grid.css" rel="stylesheet"> -->
	<link href="../vendor/bootstrap-grid.css" rel="stylesheet">
	<meta charset="utf-8" />
	<link rel="apple-touch-icon" sizes="76x76" href="../assets/img/favicon.ico">
	<link rel="icon" type="image/png" href="../assets/img/favicon.ico">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
	<meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0, shrink-to-fit=no'
		name='viewport' />



	<!-- Font Awesome Icons -->

	<!-- Main CSS -->
	<link href="../assets/css/main.css" rel="stylesheet" />

	<!-- Animation CSS -->
	<link href="../vendor/aos.css" rel="stylesheet" />
	<link rel="stylesheet" type="text/css" href="../assets/font/iconfont.css" />
	<style>
		.tree {
			padding-top: 10px;
			border: 1px solid #ced4da;
			display: block;
			margin: auto;
			position: relative;
			padding-left: 20px;
		}

		a {
			text-decoration: none;
			color: #434b5a;
		}

		.synTree .iconxiangyou {
			cursor: pointer;
		}

		.synTree span {
			position: relative;
			top: -6px;
			left: 10px;
			color: #010102;
			cursor: default;
		}

		.leg_tree li {
			list-style-type: none;
			margin-left: -10px;
			position: relative;
			line-height: 22px;
		}

		.leg_tree li a {
			position: absolute;
			top: -4px;
			padding: 0px 10px;
		}

		.iconxiangyou {
			position: absolute;
			top: -5px;
			left: -10px;
		}

		.leg_tree li i {
			font-size: 14px;
		}

		.leg_tree li i~i:before {
			position: relative;
			top: -3px;
			left: 5px;
		}

		.tree input {
			cursor: pointer;
		}

		.tree span {
			font-size: 13px;
			cursor: pointer;
			display: inline-block;
			border: 1px solid #e2e2e2;
			width: 10px;
			line-height: 8px;
			text-align: center;
			height: 10px;
			background-color: whitesmoke;
			position: absolute;
			left: 8px;
			top: 4px;
		}

		.tree ul span {
			left: -16px;
		}

		.tree ul {
			list-style-type: none;
			margin-top: 0px;
			position: relative;
		}

		.label {
			width: 14px;
			height: 14px;
			display: inline-flex;
			border: 1px solid #a5a5a5;
			border-radius: 3px;
		}

		.label i {
			color: #0095ff;
			position: absolute;
			top: -2px;
			left: -1px;
			font-size: 18px !important;
		}

		.label:hover {
			box-shadow: 0 0 4px 0px #a0aefb;
		}

		/*.label i:hover {
			box-shadow: 0 0 4px 0px #a0aefb;
		}*/
		.isShow {
			position: absolute;
			top: -3px;
			left: -20px;
		}

		input {
			display: none;
		}

		.isShow {
			width: 14px;
			margin-right: 5px;
		}
	</style>
</head>

<body>


	<main class="container">

		<!--------------------------------------
PRICING
--------------------------------------->
		<section class="pt-4 pb-5">
			<div class="col-md-12" id="probation">
				<form id="form1" class="layui-form" lay-filter="applyMadeForm">
					<div class="row form-group">
						<div class="col">
							<p><i style="color: red;">*</i> 定制名称</p>
							<input type="text" class="form-control name" placeholder="请填写定制名称" required="" name="name">
							<span></span>
						</div>
					</div>
					<div class="row form-group">
						<div class="col">
							<label>需求描述</label>
							<textarea class="form-control " rows="3" placeholder="请填写需求描述" name="productDetail"></textarea>
						</div>
					</div>
					<div class="row form-group">
						<div class="col">
							<label><i style="color: red;">*</i> 联系人</label>
							<input type="text" class="form-control" placeholder="请填写联系人" required="" name="contact">
							<span></span>
						</div>
						<div class="col">
							<label><i style="color: red;">*</i> 联系方式</label>
							<input type="text" class="form-control" placeholder="请填写联系方式" required="" name="phone">
							<span></span>
						</div>
					</div>
					 <div class="row form-group">
<!--			<div class="col">-->
<!--				<label>计价方式</label>-->
<!--				<select class="form-control">-->
<!--					<option>按次数计费</option>-->
<!--					<option>按月计费</option>-->
<!--					<option>按流量计费</option>-->
<!--				</select>-->
<!--			</div>-->
			<div class="col">
				<label>价格</label>
				<input type="number" class="form-control" placeholder="请填写金额" required="" name="price">
			</div>
		</div>
					<button type="submit" class="btn btn-cyan btn-round text-white submitBtn"
							style="float: right;">提交</button>
					<button type="submit" class="btn btn-cyan btn-round text-white saveBtn"
							style="float: right;margin-left: 5px;">保存</button>
				</form>
			</div>
		</section>



		<!--------------------------------------
JAVASCRIPTS
--------------------------------------->
		<script src="../vendor/jquery.min.js" type="text/javascript"></script>
		<script src="../assets/layui/layui.js" type="text/javascript"></script>
		<script src="../js/tool.js" type="text/javascript"></script>



		<script>
			$(function () {
				var dataInfo = {};
				const form=layui.form;
				console.log(' parent.window.ApplyMadePopId',  parent.window.ApplyMadePopId)
				//获取详情
				function DataRequest() {
					$.ajax({
       					timeout:30000,
						type: 'GET',
						url: window.Http + "/CustomizeRequest/" + parent.window.ApplyMadePopId,
						headers: {
							'Authorization': "Bearer " + sessionStorage.getItem('Token')
						},
						success: function (res) {
							if (res.code === 200) {
								dataInfo=res.data;
								form.val('applyMadeForm',res.data)
							}else {
								layer.msg('获取详情失败')
							}
						}
					})
				}
				DataRequest()
				// 表单检验
				function check() {
					var regnickn = /^[\u4E00-\u9FA5A-Za-z]{2,10}$/  //别名
					// var regemailn = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/  //邮箱
					let regtel = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/ //电话号码
					var nickn = $('[name="name"]');
					// var emailn = $('#email');
					var tel = $('[name="phone"]');
					var contact = $('[name="contact"]')
					regexp(nickn, regnickn, '请正确输入定制名称');
					regexp(contact, regnickn, '请正确输入联系人');
					regexp(tel, regtel, '请正确输入电话号码');
					// 表单验证的函数
					function regexp(ele, reg, str) {
						$(ele).blur(function () {
							console.log(ele)
							if (!reg.test(this.value)) {
								this.nextElementSibling.style = 'color:red;';
								this.nextElementSibling.innerHTML = str;
								$(".submitBtn").attr('disabled', true)
							} else {
								this.nextElementSibling.innerHTML = ""
								$(".submitBtn").attr('disabled', false)
							}
						})
					};
				}
				check()
				/**
				 * @description:处理请求参数
				 * @return {Object}
				 * @param status -1 新增 2保存
				 */

				function handleParams(status){
					const formData = layui.form.val("applyMadeForm");
					console.log('formData', formData)
					formData.type=dataInfo.type;
					formData.id=dataInfo.id;
					formData.contentId=dataInfo.contentId
					formData.status=status
					return formData;
				}
				//提交
				$("body").on("click", '.submitBtn', function (e) {
					e.preventDefault();
					const formData=handleParams(2)
					$.ajax({
       					timeout:30000,
						url: window.Http + "/CustomizeRequest/edit",
						type: 'PUT',
						headers: {
							'Authorization': "Bearer " + sessionStorage.getItem('Token')
						},
						data: JSON.stringify(formData),
						contentType: "application/json",
						success: function (res) {
							console.log(res)
							if (res.code === 200) {
								layer.msg("修改成功，请等待审核！");
								setTimeout(function () {
									let index = parent.layer.getFrameIndex(window.name);
									//再执行关闭
									parent.layer.close(index);
									//parent.layer.close(1); //再执行关闭
								}, 1000)
							} else {
								layer.msg(res.msg);
							}
						}
					})

				})

				$('.saveBtn').on('click',function () {
					const params=handleParams(-1)
					$.ajax({
						timeout:30000,
						url: window.Http + "/CustomizeRequest/edit",
						type: 'POST',
						headers: {
							'Authorization': "Bearer " + sessionStorage.getItem('Token')
						},
						data: JSON.stringify(params),
						contentType: "application/json",
						success: function (res) {
							if (res.code === 200) {
								layer.msg("保存成功");
								setTimeout(function () {
									let index = parent.layer.getFrameIndex(window.name);
									//再执行关闭
									parent.layer.close(index);
									// parent.layer.close(2); //再执行关闭
								}, 1000)
							} else {
								layer.msg(res.msg);
							}
						}
					})
				})
			})
		</script>

</body>

</html>
